<?php
/**
 * 城市提升-地方车展控制器
 * @author jianhui
 *
 */
class CarProject extends MY_Controller{
    function CarProject(){
        parent::MY_Controller();
        //设置导航选中
        $this->navbarFocus = 'CarBudget';
    }
    /**
     * 添加车展
     */
    function add(){
        $this->load->model('carProjectModel');
        if ($_POST){
            $id = (int)$this->input->post('id');
            $data = array(
                'storeId'   => $this->user['userId'],
                'procId'    => (int)$this->input->post('procId'),
                'isBubao'   => (int)$this->input->post('isBubao'),
                'name'      => $this->input->post('name'),
                'level'     => (int)$this->input->post('level'),
                'startTime' => $this->input->post('startTime'),
                'endTime'   => $this->input->post('endTime'),
                'address'   => $this->input->post('address'),
                'isSync'    => 0,
            );
            $data['procId'] || showError('主线ID不能为空');
            $data['name'] || showError('请输入车展名称');
            $data['level'] || showError('请选择车展等级');
            $data['startTime'] || showError('请选择活动开始时间');
            $data['endTime'] || showError('请选择活动结束时间');
            $data['address'] || showError('请输入场馆地址');
            if ($id){
                $id = $this->carProjectModel->edit($id, $data);
            }else{
                if ($this->carProjectModel->getData(array('storeId'=>$data['storeId'], 'procId'=>$data['procId']))){
                    showError('车展项目只允许添加一个');
                }
                $data['createTime'] = time();
                $id = $this->carProjectModel->add($data);
            }
            if ($id){
                showSuccess('保存车展成功', printUrl('CarProject', 'childDetail', array('procId'=>$data['procId'], 'projectId'=>$id)));
            }else{
                showError('保存车展失败');
            }
        }else{
            $projectId = (int)$this->input->get('projectId');
            $procId = (int)$this->input->get('procId');
            $isBubao = (int)$this->input->get('isBubao');
            if ($projectId){
                $projectData = $this->carProjectModel->getData(array('id'=>$projectId,'storeId'=>$this->user['userId']));
                $projectData || showError('您要修改的车展数据不存在');
                in_array($projectData['budgetAuditRs'], array(-1,0,3)) || showError('项目已审核，不允许修改');
                $this->viewData['projectData'] = $projectData;
                $isBubao = $projectData['isBubao'];
                $procId = $projectData['procId'];
            }else{
                //判断是否已存在，已存在则提示不能再次添加
                $projectList = $this->carProjectModel->getNewList(array('procId'=>$procId,'isBubao'=>$isBubao), NULL, NULL, '', 'id desc');
                $projectList && showError('车展项目只能添加一个');
            }
            $procId || showError('请选择要添加项目的流程');
            $this->viewData['procId'] = $procId;
            $this->viewData['isBubao'] = $isBubao;
            //选中状态
            $isBubao && $this->navbarFocus = 'Supplement';
            //面包屑
            $this->viewData['breadcrumb'][] = array('url'=>printUrl('CarBudget'.($isBubao?'Again':''), 'storeList'),'title'=>'车展基金'.($isBubao?'补报':'').'预算列表');
            $this->viewData['breadcrumb'][] = array('url'=>printUrl('CarBudget'.($isBubao?'Again':''), 'storeEdit', array('procId'=>$procId)),'title'=>'车展基金'.($isBubao?'补报':'').'预算编辑');
            $this->viewData['breadcrumb'][] = array('url'=>'','title'=>'车展基金'.($projectId ? '修改':'添加') );
            //主线流程数据
            $this->load->model('carProcessModel');
            $procData = $this->carProcessModel->getNewData(array('id'=>$procId));
            $this->viewData['procData'] = $procData;
            //是否为特殊补报
            $this->viewData['isSpecialBubao'] = $this->auth->isCarBudgetEdit($procData);
            
            $this->load->view('CarProject/add', $this->viewData);
        }
    }
    /**
     * 车展删除
     */
    function del(){
        $projectId = (int)$this->input->post('projectId');
        $projectId || showError('请选择要删除的项目ID');
        $this->load->model('carProjectModel');
        if ($projectId){
            $this->load->model('carGxModel');
            $this->carGxModel->del(array('projectId'=>$projectId,'storeId'=>$this->user['userId']),'*');
            $this->load->model('carRentModel');
            $this->carRentModel->del(array('projectId'=>$projectId,'storeId'=>$this->user['userId']),'*');
            $this->load->model('carMatchingModel');
            $this->carMatchingModel->del(array('projectId'=>$projectId,'storeId'=>$this->user['userId']),'*');
            $this->carProjectModel->del(array('id'=>$projectId,'storeId'=>$this->user['userId']));
            showSuccess('删除车展成功');
        }else{
            showError('删除车展失败');
        }
    }
    /**
     * 地方车展明细
     */
    function childDetail() {
        $procId = (int)$this->input->get('procId');
        $procId || showError('请选择主线序号');
        $this->viewData['procId'] = $procId;
        $projectId = (int)$this->input->get('projectId');
        $projectId || showError('请选择车展');
        $this->viewData['projectId'] = $projectId;
        //车展主线
        $this->load->model('carProcessModel');
        $procData = $this->carProcessModel->getData(array('id'=>$procId,'storeId'=>$this->user['userId']));
        $procData || showError('车展双月数据不存在');
        //车展模型
        $this->load->model('carProjectModel');
        $projectData = $this->carProjectModel->getNewData(array('id'=>$projectId,'storeId'=>$this->user['userId']));
        $projectData || showError('车展数据不存在');
        $this->viewData['projectData'] = $projectData;
        //选中状态
        $projectData['isBubao'] && $this->navbarFocus = 'Supplement';
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('CarBudget'.($projectData['isBubao']?'Again':''), 'storeList'),'title'=>'车展基金'.($projectData['isBubao']?'补报':'').'列表');
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('CarBudget'.($projectData['isBubao']?'Again':''), 'storeEdit', array('procId'=>$procId)),'title'=>'车展基金'.($projectData['isBubao']?'补报':'').'预算编辑');
        $this->viewData['breadcrumb'][] = array('url'=>'','title'=>'车展基金明细编辑');
        //金额明细
        $this->viewData['moneyDetail'] = $this->carProjectModel->getDetailMoney($projectId);
        //导入金额模型
        $this->load->model('importMoneyModel');
        //车展广宣
        $this->load->model('carGxModel');
        $this->viewData['gxList'] = $this->carGxModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
        $this->viewData['subsidyGx'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 31, $procData['year']);
        //车展场租
        $this->load->model('carRentModel');
        $this->viewData['rentList'] = $this->carRentModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
        //$this->viewData['rentQiTotal'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 32, $procData['year']);
        //车展配套
        $this->load->model('carMatchingModel');
        $this->viewData['matchingList'] = $this->carMatchingModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
        $this->viewData['subsidyMatching'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 33, $procData['year']);
        //标记动作
        $this->viewData['action'] = 'edit';
        $this->load->view('CarProject/childDetail', $this->viewData);
    }
    /**
     * 预算查看
     */
    function budgetCheck(){
        $procId = (int)$this->input->post('procId');
        $procId || showError('请选择主线序号');
        $this->viewData['procId'] = $procId;
        $projectId = (int)$this->input->post('projectId');
        $projectId || showError('请选择车展');
        $this->viewData['projectId'] = $projectId;
        //车展主线
        $this->load->model('carProcessModel');
        $procData = $this->carProcessModel->getData(array('id'=>$procId));
        $procData || showError('车展双月数据不存在');
        //项目模型
        $this->load->model('carProjectModel');
        $this->viewData['projectData'] = $this->carProjectModel->getNewData(array('id'=>$projectId));
        $this->viewData['projectData'] || showError('车展数据不存在');
        //金额明细
        $this->viewData['moneyDetail'] = $this->carProjectModel->getDetailMoney($projectId);
        //导入金额模型
        $this->load->model('importMoneyModel');
        //车展广宣
        $this->load->model('carGxModel');
        $this->viewData['gxList'] = $this->carGxModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
        $this->viewData['subsidyGx'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 31, $procData['year']);
        //车展场租
        $this->load->model('carRentModel');
        $this->viewData['rentList'] = $this->carRentModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
        //$this->viewData['rentQiTotal'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 32, $procData['year']);
        //车展配套
        $this->load->model('carMatchingModel');
        $this->viewData['matchingList'] = $this->carMatchingModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
        $this->viewData['subsidyMatching'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 33, $procData['year']);
        //标记动作
        $this->viewData['action'] = 'check';
        $this->load->view('CarProject/budgetCheck', $this->viewData);
    }
    /**
     * 预算提交
     */
    function budgetSubmit(){
        $projectId = (int)$this->input->post('projectId');
        $projectId || showError('请选择车展');
        //项目模型
        $this->load->model('carProjectModel');
        $projectData = $this->carProjectModel->getNewData(array('id'=>$projectId,'storeId'=>$this->user['userId']));
        $projectData || showError('车展数据不存在');
        $this->viewData['projectData'] = $projectData; 
        if ($this->carProjectModel->edit($projectId, array('budgetAuditRs'=>0,'budgetSubTime'=>time()) )){
            //车展广宣
            $this->load->model('carGxModel');
            $this->carGxModel->edit(array('projectId'=>$projectId,'storeId'=>$this->user['userId'],'budgetAuditRs'=>-1), array('budgetAuditRs'=>0,'budgetSubTime'=>time()), '*');
            //车展场租
            $this->load->model('carRentModel');
            $this->carRentModel->edit(array('projectId'=>$projectId,'storeId'=>$this->user['userId'],'budgetAuditRs'=>-1), array('budgetAuditRs'=>0,'budgetSubTime'=>time()), '*');
            //车展配套
            $this->load->model('carMatchingModel');
            $this->carMatchingModel->edit(array('projectId'=>$projectId,'storeId'=>$this->user['userId'],'budgetAuditRs'=>-1), array('budgetAuditRs'=>0,'budgetSubTime'=>time()), '*');
            //更新统计金额
            $this->carProjectModel->updateMoney($projectId);
            showSuccess('提交项目预算申请成功', printUrl('CarBudget'.($projectData['isBubao']?'Again':''), 'storeEdit', array('procId'=>$this->viewData['projectData']['procId'])));
        }else{
            showError('提交车展预算申请失败');
        }
    }
    /**
     * 预算审核
     */
    function budgetAudit(){
        $this->load->model('carProjectModel');
        $this->load->model('carGxModel');
        $this->load->model('carRentModel');
        $this->load->model('carMatchingModel');
        if ($_POST){
            $projectId = (int)$this->input->get('projectId');
            $projectId || showError('请选择项目');
            $projectData = $this->carProjectModel->getNewData(array('id'=>$projectId));
            if ($projectData['settleAuditRs'] > -1){
                showError('项目已申请结算,无法进行预算审核');
            }
            $gxData = $this->input->post('gx');
            $rentData = $this->input->post('rent');
            $matchingData = $this->input->post('matching');
            if (!$gxData && !$rentData && !$matchingData){
                showError('请还未选择审核项');
            }
            if ($gxData){
                foreach ($gxData as $k => $v){
                    $this->carGxModel->budgetAudit((int)$k, (int)$v['budgetAuditRs'], $this->user);
                    $this->carGxModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($rentData){
                foreach ($rentData as $k => $v){
                    $this->carRentModel->budgetAudit((int)$k, (int)$v['budgetAuditRs'], $this->user);
                    $this->carRentModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($matchingData){
                foreach ($matchingData as $k => $v){
                    $this->carMatchingModel->budgetAudit((int)$k, (int)$v['budgetAuditRs'], $this->user);
                    $this->carMatchingModel->updateMoney((int)$k);//更新金额
                }
            }
            $this->carProjectModel->edit($projectId, array('budgetAuditDetail'=>1,'budgetAuditRole'=>$this->user['userRole']));
            $this->carProjectModel->budgetUpdateStatus($projectId);
            //更新项目金额
            $this->carProjectModel->updateMoney($projectId);
            showSuccess('审核成功');
        }else{
            $procId = (int)$this->input->get('procId');
            $procId || showError('请选择主线序号');
            $this->viewData['procId'] = $procId;
            $projectId = (int)$this->input->get('projectId');
            $projectId || showError('请选择车展');
            $this->viewData['projectId'] = $projectId;
            //车展主线
            $this->load->model('carProcessModel');
            $procData = $this->carProcessModel->getData(array('id'=>$procId));
            $procData || showError('车展双月数据不存在');
            //项目模型
            $this->viewData['projectData'] = $this->carProjectModel->getNewData(array('id'=>$projectId));
            $this->viewData['projectData'] || showError('车展数据不存在');
            //导入金额模型
            $this->load->model('importMoneyModel');
            //金额明细
            $this->viewData['moneyDetail'] = $this->carProjectModel->getDetailMoney($projectId);
            //车展广宣
            $this->viewData['gxList'] = $this->carGxModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
            $this->viewData['subsidyGx'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 31, $procData['year']);
            //车展场租
            $this->viewData['rentList'] = $this->carRentModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
            //$this->viewData['rentQiTotal'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 32, $procData['year']);
            //车展配套
            $this->viewData['matchingList'] = $this->carMatchingModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId));
            $this->viewData['subsidyMatching'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 33, $procData['year']);
            //标记动作
            $this->viewData['action'] = 'audit';
            $this->load->view('CarProject/budgetAudit', $this->viewData);
        }
    }
    /**
     * 结算申请
     */
    function settleSubmit(){
        $this->load->model('carProjectModel');
        $this->load->model('carGxModel');
        $this->load->model('carRentModel');
        $this->load->model('carMatchingModel');
        if ($_POST){
            $projectId = (int)$this->input->get('projectId');
            $projectId || showError('请选择车展');
            $gxData = $this->input->post('gx');//广宣
            $rentData = $this->input->post('rent');//场租
            $matchingData = $this->input->post('matching');//配套
            if (!$gxData && !$rentData && !$matchingData){
                showError('您的结算申请数据为空');
            }
            if ($gxData){
                foreach ($gxData as $k => $v){
                    if ((int)$v['isSettle']){
                        (float)$v['settleApply'] >= 0 || showError('编号为【'.$k.'】的广宣实际费用为空');
                        (int)$v['fileId'] || showError('编号为【'.$k.'】的广宣自证照片为空');
                    }
                }
            }
            if ($rentData){
                foreach ($rentData as $k => $v){
                    if ((int)$v['isSettle']){
                        (float)$v['settleApply'] >= 0 || showError('编号为【'.$k.'】的场租实际费用为空');
                        (int)$v['settleQiTotalType'] || showError('编号为【'.$k.'】的场租启辰店实际出资总额为空');
                        if ((int)$v['settleQiTotalType'] == -1 && (float)$v['settleQiTotal'] < 0){
                            showError('编号为【'.$k.'】的场租启辰店实际出资总额为空');
                        }
                        (int)$v['fileId'] || showError('编号为【'.$k.'】的场租自证照片为空');
                    }
                }
            }
            if ($matchingData){
                foreach ($matchingData as $k => $v){
                    if ((int)$v['isSettle']){
                        (float)$v['settleApply'] >= 0 || showError('编号为【'.$k.'】的配套实际费用为空');
                        (int)$v['fileId'] || showError('编号为【'.$k.'】的配套自证照片为空');
                    }
                }
            }
            if ($gxData){
                foreach ($gxData as $k => $v){
                    $this->carGxModel->edit((int)$k, array(
                        'settleAuditRole' => 0,
                        'settleAuditRs'=>(int)$v['isSettle'] ? 0 : -1,
                        'isSettle'=>(int)$v['isSettle'],
                        'fileId' => (int)$v['fileId'],
                        'settleApply' => (float)$v['settleApply'],
                        'settleSubTime' => time()
                    ));
                    $this->carGxModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($rentData){
                $qiTotalType = $this->config->item('carshowQiTotalType');
                foreach ($rentData as $k => $v){
                    $settleQiTotalType = (int)$v['settleQiTotalType'];
                    if ($settleQiTotalType != -1 && isset($qiTotalType[$settleQiTotalType])){
                        $settleQiTotal = $qiTotalType[$settleQiTotalType];
                    }else{
                        $settleQiTotal = (float)$v['settleQiTotal'];
                    }
                    $this->carRentModel->edit((int)$k, array(
                        'settleAuditRole' => 0,
                        'settleAuditRs'=>(int)$v['isSettle'] ? 0 : -1,
                        'isSettle'=>(int)$v['isSettle'],
                        'fileId' => (int)$v['fileId'],
                        'settleApply' => (float)$v['settleApply'],
                        'settleQiTotalType' => $settleQiTotalType,
                        'settleQiTotal' => $settleQiTotal,
                        'settleSubTime' => time()
                    ));
                    $this->carRentModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($matchingData){
                foreach ($matchingData as $k => $v){
                    $this->carMatchingModel->edit((int)$k, array(
                        'settleAuditRole' => 0,
                        'settleAuditRs'=>(int)$v['isSettle'] ? 0 : -1,
                        'isSettle'=>(int)$v['isSettle'],
                        'fileId' => (int)$v['fileId'],
                        'settleApply' => (float)$v['settleApply'],
                        'settleSubTime' => time()
                    ));
                    $this->carMatchingModel->updateMoney((int)$k);//更新金额
                }
            }
            $this->carProjectModel->edit($projectId,array(
                'settleSubTime'=>time(),
            ));
            $this->carProjectModel->settleUpdateStatus($projectId);
            $this->carProjectModel->updateMoney($projectId);
            showSuccess('提交结算申请成功');
        }else{
            $procId = (int)$this->input->get('procId');
            $procId || showError('请选择主线序号');
            $this->viewData['procId'] = $procId;
            $projectId = (int)$this->input->get('projectId');
            $projectId || showError('请选择车展');
            $this->viewData['projectId'] = $projectId;
            //车展主线
            $this->load->model('carProcessModel');
            $procData = $this->carProcessModel->getData(array('id'=>$procId));
            $procData || showError('车展双月数据不存在');
            //项目模型
            $this->viewData['projectData'] = $this->carProjectModel->getNewData(array('id'=>$projectId,'storeId'=>$this->user['userId']));
            $this->viewData['projectData'] || showError('车展数据不存在');
            //导入金额模型
            $this->load->model('importMoneyModel');
            //金额明细
            $this->viewData['moneyDetail'] = $this->carProjectModel->getDetailMoney($projectId);
            //车展广宣
            $this->viewData['gxList'] = $this->carGxModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
            $this->viewData['subsidyGx'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 31, $procData['year']);
            //车展场租
            $this->viewData['rentList'] = $this->carRentModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
            //$this->viewData['rentQiTotal'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 32, $procData['year']);
            //车展配套
            $this->viewData['matchingList'] = $this->carMatchingModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
            $this->viewData['subsidyMatching'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 33, $procData['year']);
            //标记动作
            $this->viewData['action'] = 'edit';
            $this->load->view('CarProject/settleSubmit', $this->viewData);
        }
    }
    /**
     * 结算查看
     */
    function settleCheck(){
        $procId = (int)$this->input->post('procId');
        $procId || showError('请选择主线序号');
        $this->viewData['procId'] = $procId;
        $projectId = (int)$this->input->post('projectId');
        $projectId || showError('请选择车展');
        $this->viewData['projectId'] = $projectId;
        //载入模型
        $this->load->model('carProjectModel');
        $this->load->model('carGxModel');
        $this->load->model('carRentModel');
        $this->load->model('carMatchingModel');
        //车展主线
        $this->load->model('carProcessModel');
        $procData = $this->carProcessModel->getData(array('id'=>$procId));
        $procData || showError('车展双月数据不存在');
        //项目模型
        $this->viewData['projectData'] = $this->carProjectModel->getNewData(array('id'=>$projectId));
        $this->viewData['projectData'] || showError('车展数据不存在');
        //导入金额模型
        $this->load->model('importMoneyModel');
        //金额明细
        $this->viewData['moneyDetail'] = $this->carProjectModel->getDetailMoney($projectId);
        //车展广宣
        $this->viewData['gxList'] = $this->carGxModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
        $this->viewData['subsidyGx'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 31, $procData['year']);
        //车展场租
        $this->viewData['rentList'] = $this->carRentModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
        //$this->viewData['rentQiTotal'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 32, $procData['year']);
        //车展配套
        $this->viewData['matchingList'] = $this->carMatchingModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
        $this->viewData['subsidyMatching'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 33, $procData['year']);
        //标记动作
        $this->viewData['action'] = 'check';
        $this->load->view('CarProject/settleCheck', $this->viewData);
    }
    /**
     * 结算审核
     */
    function settleAudit(){
        $this->load->model('carProjectModel');
        $this->load->model('carGxModel');
        $this->load->model('carRentModel');
        $this->load->model('carMatchingModel');
        if ($_POST){
            $projectId = (int)$this->input->post('projectId');
            $projectId || showError('请选择车展');
            $gxData = $this->input->post('gx');//广宣
            $rentData = $this->input->post('rent');//场租
            $matchingData = $this->input->post('matching');//配套
            if (!$gxData && !$rentData && !$matchingData){
                showError('您的结算申请数据为空');
            }
            if ($gxData){
                foreach ($gxData as $k => $v){
                    $this->carGxModel->settleAudit((int)$k, (int)$v['settleAuditRs'], $this->user);
                    $this->carGxModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($rentData){
                foreach ($rentData as $k => $v){
                    $this->carRentModel->settleAudit((int)$k, (int)$v['settleAuditRs'], $this->user);
                    $this->carRentModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($matchingData){
                foreach ($matchingData as $k => $v){
                    $this->carMatchingModel->settleAudit((int)$k, (int)$v['settleAuditRs'], $this->user);
                    $this->carMatchingModel->updateMoney((int)$k);//更新金额
                }
            }
            $this->carProjectModel->edit($projectId, array('settleAuditDetail'=>1,'settleAuditRole'=>$this->user['userRole']));
            $this->carProjectModel->settleUpdateStatus($projectId);
            //更新车展金额
            $this->carProjectModel->updateMoney($projectId);
            showSuccess('审核成功');
        }else{
            $procId = (int)$this->input->get('procId');
            $procId || showError('请选择主线序号');
            $this->viewData['procId'] = $procId;
            $projectId = (int)$this->input->get('projectId');
            $projectId || showError('请选择车展');
            $this->viewData['projectId'] = $projectId;
            //车展主线
            $this->load->model('carProcessModel');
            $procData = $this->carProcessModel->getData(array('id'=>$procId));
            $procData || showError('车展双月数据不存在');
            //项目模型
            $this->viewData['projectData'] = $this->carProjectModel->getNewData(array('id'=>$projectId));
            $this->viewData['projectData'] || showError('车展数据不存在');
            //导入金额模型
            $this->load->model('importMoneyModel');
            //金额明细
            $this->viewData['moneyDetail'] = $this->carProjectModel->getDetailMoney($projectId);
            //车展广宣
            $this->viewData['gxList'] = $this->carGxModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'isSettle'=>1,'settleApply >'=>0));
            $this->viewData['subsidyGx'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 31, $procData['year']);
            //车展场租
            $this->viewData['rentList'] = $this->carRentModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'isSettle'=>1,'settleApply >'=>0));
            //$this->viewData['rentQiTotal'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 32, $procData['year']);
            //车展配套
            $this->viewData['matchingList'] = $this->carMatchingModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'isSettle'=>1,'settleApply >'=>0));
            $this->viewData['subsidyMatching'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 33, $procData['year']);
            //标记动作
            $this->viewData['action'] = 'audit';
            $this->load->view('CarProject/settleAudit', $this->viewData);
        }
    }
    /**
     * 修改金额
     */
    function settleChange(){
        $this->load->model('carProjectModel');
        $this->load->model('carGxModel');
        $this->load->model('carRentModel');
        $this->load->model('carMatchingModel');
        if ($_POST){
            $projectId = (int)$this->input->post('projectId');
            $projectId || showError('请选择车展');
            $gxData = $this->input->post('gx');//广宣
            $rentData = $this->input->post('rent');//场租
            $matchingData = $this->input->post('matching');//配套
            if (!$gxData && !$rentData && !$matchingData){
                showError('您的提交的数据为空');
            }
            if ($gxData){
                foreach ($gxData as $k => $v){
                    $this->carGxModel->edit((int)$k, array(
                        'settleApply' => (float)$v['settleApply'],
                        'settleAudit' => (int)$v['settleAuditRs'] == 1 ? (float)$v['settleApply'] : 0,
                    ));
                    $this->carGxModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($rentData){
                foreach ($rentData as $k => $v){
                    $this->carRentModel->edit((int)$k, array(
                        'settleApply' => (float)$v['settleApply'],
                    ));
                    $this->carRentModel->updateMoney((int)$k);//更新金额
                }
            }
            if ($matchingData){
                foreach ($matchingData as $k => $v){
                    $this->carMatchingModel->edit((int)$k, array(
                        'settleApply' => (float)$v['settleApply'],
                        'settleAudit' => (int)$v['settleAuditRs'] == 1 ? (float)$v['settleApply'] : 0,
                    ));
                    $this->carMatchingModel->updateMoney((int)$k);//更新金额
                }
            }
            $this->carProjectModel->settleUpdateStatus($projectId);
            $this->carProjectModel->updateMoney($projectId);
            showSuccess('保存成功');
        }else{
            $procId = (int)$this->input->get('procId');
            $procId || showError('请选择主线序号');
            $this->viewData['procId'] = $procId;
            $projectId = (int)$this->input->get('projectId');
            $projectId || showError('请选择车展');
            $this->viewData['projectId'] = $projectId;
            //车展主线
            $this->load->model('carProcessModel');
            $procData = $this->carProcessModel->getData(array('id'=>$procId));
            $procData || showError('车展双月数据不存在');
            //项目模型
            $this->viewData['projectData'] = $this->carProjectModel->getNewData(array('id'=>$projectId));
            $this->viewData['projectData'] || showError('车展数据不存在');
            //导入金额模型
            $this->load->model('importMoneyModel');
            //金额明细
            $this->viewData['moneyDetail'] = $this->carProjectModel->getDetailMoney($projectId);
            //车展广宣
            $this->viewData['gxList'] = $this->carGxModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
            $this->viewData['subsidyGx'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 31, $procData['year']);
            //车展场租
            $this->viewData['rentList'] = $this->carRentModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
            //$this->viewData['rentQiTotal'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 32, $procData['year']);
            //车展配套
            $this->viewData['matchingList'] = $this->carMatchingModel->getNewList(array('projectId'=>$projectId,'procId'=>$procId,'budgetAuditRs'=>1));
            $this->viewData['subsidyMatching'] = $this->importMoneyModel->getMoney($procData['storeId'], $procData['timeUnit'], 33, $procData['year']);
            //标记动作
            $this->viewData['action'] = 'change';
            $this->load->view('CarProject/settleSubmit', $this->viewData);
        }
    }
}